# 查找NanoSDK库
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
find_package(NanoSDK REQUIRED)

# 查找JSON-C库
find_package(PkgConfig REQUIRED)
pkg_check_modules(JSON-C json-c REQUIRED)

# 查找OpenSSL库
find_package(OpenSSL REQUIRED)

# 包含目录
include_directories(
    ${CMAKE_SOURCE_DIR}/include
    ${NANOSDK_INCLUDE_DIRS}
    ${JSON-C_INCLUDE_DIRS}
)

# 添加可执行文件
add_executable(mqtt_ota_nanosdk
    main.c
    mqtt_ota.c
)

# 链接库
target_link_libraries(mqtt_ota_nanosdk
    ${NANOSDK_LIBRARIES}
    ${JSON-C_LIBRARIES}
    OpenSSL::SSL
    OpenSSL::Crypto
    m
    pthread
)

# 安装可执行文件
install(
    TARGETS mqtt_ota_nanosdk
    RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
    PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)

# 安装头文件
install(
    FILES ${CMAKE_SOURCE_DIR}/include/mqtt_ota.h
    DESTINATION ${CMAKE_INSTALL_PREFIX}/include/mqtt_ota
)
